<template>
  <div class="type-list">
    <!-- 页面头部 -->
    <div class="page-header">
      <h2>类型管理</h2>
      <p>管理系统中的所有商品类型信息</p>
    </div>
    
    <div class="content-wrapper">
      <!-- 搜索和操作栏 -->
      <div class="search-action-bar">
        <div class="search-box">
          <input 
            type="text" 
            placeholder="搜索类型名称..." 
            v-model="searchQuery"
            @keyup.enter="searchTypes"
            class="search-input"
          >
          <button class="search-btn" @click="searchTypes">🔍</button>
        </div>
        
        <div class="filter-controls">
          <select v-model="statusFilter" class="filter-select">
            <option value="">全部状态</option>
            <option value="1">启用</option>
            <option value="0">禁用</option>
          </select>
        </div>
        
        <button class="btn btn-primary create-btn" @click="addType">
          <i class="icon">➕</i>
          创建类型
        </button>
      </div>
      
      <!-- 加载状态 -->
      <div v-if="loading" class="loading-container">
        <div class="loading-spinner"></div>
        <p>正在加载类型数据...</p>
      </div>
      
      <!-- 空状态 -->
      <div v-else-if="filteredTypes.length === 0" class="empty-state">
        <div class="empty-icon">📁</div>
        <h3>暂无类型数据</h3>
        <p>{{ searchQuery || statusFilter ? '没有找到匹配的类型' : '还没有创建任何类型' }}</p>
        <button class="btn btn-primary" @click="addType" v-if="!searchQuery && !statusFilter">
          创建第一个类型
        </button>
      </div>
      
      <!-- 类型网格 -->
      <div v-else class="types-grid" :key="updateKey">
        <div 
          class="type-card" 
          v-for="type in paginatedTypes" 
          :key="`${type.typeId}-${type.status}-${updateKey}`"
          :class="{ inactive: type.status === '0' }"
        >
          <div class="card-content">
            <div class="type-info">
              <h3 class="type-title">{{ type.typeName }}</h3>
              <div class="type-meta">
                <span class="type-id">ID: {{ type.typeId }}</span>
                <span class="type-status" :class="type.status === '1' ? 'status-active' : 'status-inactive'">
                  {{ type.status === '1' ? '启用' : '禁用' }}
                </span>
              </div>
            </div>
            
            <div class="type-details">
              <div class="detail-row">
                <span class="label">状态:</span>
                <span class="value" :class="type.status === '1' ? 'status-active' : 'status-inactive'">
                  {{ type.status === '1' ? '启用中' : '已禁用' }}
                </span>
              </div>
            </div>
            
            <div class="card-actions">
              <button class="action-btn edit" @click="editType(type)" title="编辑">✏️</button>
              <button 
                class="action-btn toggle" 
                @click="toggleStatus(type)" 
                :title="type.status === '1' ? '禁用' : '启用'"
              >
                {{ type.status === '1' ? '⏸️' : '▶️' }}
              </button>
              <button class="action-btn delete" @click="deleteType(type)" title="删除">🗑️</button>
            </div>
          </div>
        </div>
      </div>
      
      <!-- 分页组件 -->
      <div v-if="filteredTypes.length > 0" class="pagination-wrapper">
        <div class="pagination-info">
          显示第 {{ (currentPage - 1) * pageSize + 1 }} - 
          {{ Math.min(currentPage * pageSize, filteredTypes.length) }} 条，
          共 {{ filteredTypes.length }} 条记录
        </div>
        
        <div class="pagination-controls">
          <button 
            class="pagination-btn" 
            @click="currentPage = currentPage - 1"
            :disabled="currentPage <= 1"
          >
            上一页
          </button>
          
          <div class="page-numbers">
            <button 
              v-for="page in visiblePages" 
              :key="page"
              class="page-number"
              :class="{ active: page === currentPage }"
              @click="currentPage = page"
            >
              {{ page }}
            </button>
          </div>
          
          <button 
            class="pagination-btn" 
            @click="currentPage = currentPage + 1"
            :disabled="currentPage >= totalPages"
          >
            下一页
          </button>
        </div>
      </div>
      
      <!-- 添加/编辑模态框 -->
      <div class="modal-overlay" v-if="showModal" @click="closeModal">
        <div class="modal-content" @click.stop>
          <div class="modal-header">
            <h3>{{ isEditing ? '编辑类型' : '创建类型' }}</h3>
            <button class="close-btn" @click="closeModal">✕</button>
          </div>
          
          <div class="modal-body">
            <form @submit.prevent="submitType">
              <div class="form-group">
                <label>类型名称 *</label>
                <input 
                  type="text" 
                  v-model="currentType.typeName" 
                  required 
                  class="form-input"
                  placeholder="请输入类型名称"
                >
              </div>
              
              <div class="form-group">
                <label>状态</label>
                <select v-model="currentType.status" class="form-select">
                  <option value="1">启用</option>
                  <option value="0">禁用</option>
                </select>
              </div>
            </form>
          </div>
          
          <div class="form-actions">
            <button type="button" class="btn-secondary" @click="closeModal">取消</button>
            <button type="button" class="btn-primary" @click="submitType">
              {{ isEditing ? '更新' : '添加' }}
            </button>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'TypeList',
  data() {
    return {
      searchQuery: '',
      statusFilter: '',
      currentPage: 1,
      pageSize: 10,
      types: [],
      loading: false,
      showModal: false,
      updateKey: 0,
      currentType: {
        typeId: null,
        typeName: '',
        status: '1'
      }
    };
  },
  
  computed: {
    filteredTypes() {
      let filtered = this.types;
      
      // 搜索过滤
      if (this.searchQuery) {
        filtered = filtered.filter(type => 
          type.typeName.toLowerCase().includes(this.searchQuery.toLowerCase())
        );
      }
      
      // 状态过滤
      if (this.statusFilter) {
        filtered = filtered.filter(type => type.status === this.statusFilter);
      }
      
      return filtered;
    },
    
    paginatedTypes() {
      const start = (this.currentPage - 1) * this.pageSize;
      const end = start + this.pageSize;
      return this.filteredTypes.slice(start, end);
    },
    
    totalPages() {
      return Math.ceil(this.filteredTypes.length / this.pageSize);
    },
    
    isEditing() {
      return this.currentType.typeId !== null;
    },
    
    visiblePages() {
      const total = this.totalPages;
      const current = this.currentPage;
      const pages = [];
      
      if (total <= 7) {
        for (let i = 1; i <= total; i++) {
          pages.push(i);
        }
      } else {
        if (current <= 4) {
          for (let i = 1; i <= 5; i++) {
            pages.push(i);
          }
          pages.push('...');
          pages.push(total);
        } else if (current >= total - 3) {
          pages.push(1);
          pages.push('...');
          for (let i = total - 4; i <= total; i++) {
            pages.push(i);
          }
        } else {
          pages.push(1);
          pages.push('...');
          for (let i = current - 1; i <= current + 1; i++) {
            pages.push(i);
          }
          pages.push('...');
          pages.push(total);
        }
      }
      
      return pages;
    }
  },

  watch: {
    searchQuery() {
      this.currentPage = 1;
    },
    statusFilter() {
      this.currentPage = 1;
    }
  },

  mounted() {
    this.loadTypes();
  },

  methods: {
    async loadTypes() {
      this.loading = true;
      try {
        // 添加时间戳防止缓存，确保获取最新数据
        const timestamp = new Date().getTime();
        const response = await fetch(`http://localhost:8080/api/types?_t=${timestamp}`, {
          method: 'GET',
          headers: {
            'Cache-Control': 'no-cache',
            'Pragma': 'no-cache'
          }
        });
        const result = await response.json();
        
        if (result.code === 200) {
          console.log('加载类型数据:', result.data);
          // 使用Vue.set确保响应式更新
          this.$set(this, 'types', result.data || []);
          console.log('当前types数组:', this.types);
          // 更新updateKey触发视图更新
          this.updateKey++;
          // 等待下一个tick确保DOM更新
          await this.$nextTick();
        } else {
          this.showToast('加载类型列表失败: ' + (result.message || '未知错误'), 'error');
        }
      } catch (error) {
        console.error('加载类型失败:', error);
        this.showToast('加载类型列表失败', 'error');
      } finally {
        this.loading = false;
      }
    },

    async saveTypeToServer(typeData) {
      const response = await fetch('http://localhost:8080/api/types', {
        method: 'POST',
        headers: {
          'Content-Type': 'application/json'
        },
        body: JSON.stringify(typeData)
      });
      const result = await response.json();
      return result;
    },

    async updateTypeOnServer(typeId, typeData) {
      const response = await fetch(`http://localhost:8080/api/types/update/${typeId}`, {
        method: 'POST',
        headers: {
          'Content-Type': 'application/json'
        },
        body: JSON.stringify(typeData)
      });
      const result = await response.json();
      return result;
    },

    async deleteTypeFromServer(typeId) {
      const response = await fetch(`http://localhost:8080/api/types/delete/${typeId}`, {
        method: 'POST'
      });
      const result = await response.json();
      return result;
    },

    searchTypes() {
      this.currentPage = 1;
    },

    addType() {
      this.currentType = {
        typeId: null,
        typeName: '',
        status: '1'
      };
      this.showModal = true;
    },

    editType(type) {
      this.currentType = {
        typeId: type.typeId,
        typeName: type.typeName,
        status: type.status
      };
      this.showModal = true;
    },

    async deleteType(type) {
      if (confirm(`确定要删除类型 "${type.typeName}" 吗？\n删除后相关产品的分类信息也会受到影响。`)) {
        try {
          this.loading = true;
          
          const result = await this.deleteTypeFromServer(type.typeId);
          
          if (result.code === 200) {
            // 重新加载数据
            await this.loadTypes();
            this.showToast(`类型 "${type.typeName}" 已删除`, 'success');
            
            // 如果当前页没有数据了，回到上一页
            if (this.paginatedTypes.length === 0 && this.currentPage > 1) {
              this.currentPage--;
            }
          } else {
            this.showToast(result.message || '删除失败', 'error');
          }
        } catch (error) {
          this.showToast('网络错误，请重试', 'error');
        } finally {
          this.loading = false;
        }
      }
    },

    async toggleStatus(type) {
      const newStatus = type.status === '1' ? '0' : '1';
      const action = newStatus === '1' ? '启用' : '禁用';
      
      console.log('切换状态 - 原状态:', type.status, '新状态:', newStatus);
      
      if (confirm(`确定要${action}类型 "${type.typeName}" 吗？`)) {
        try {
          this.loading = true;
          const result = await this.updateTypeOnServer(type.typeId, {
            typeName: type.typeName,
            status: newStatus
          });
          
          console.log('状态更新结果:', result);
          
          if (result.code === 200) {
            console.log('状态更新成功，重新加载数据');
            // 重新加载数据
            await this.loadTypes();
            this.showToast(`类型 "${type.typeName}" 已${action}`, 'success');
          } else {
            console.error('状态更新失败:', result.message);
            this.showToast(result.message || '状态更新失败', 'error');
          }
        } catch (error) {
          console.error('状态更新网络错误:', error);
          this.showToast('网络错误，请重试', 'error');
        } finally {
          this.loading = false;
        }
      }
    },

    closeModal() {
      this.showModal = false;
      this.resetForm();
    },

    resetForm() {
      this.currentType = {
        typeId: null,
        typeName: '',
        status: '1'
      };
    },

    showToast(message, type = 'info') {
      const toast = document.createElement('div');
      toast.className = `toast toast-${type}`;
      toast.textContent = message;
      
      Object.assign(toast.style, {
        position: 'fixed',
        top: '20px',
        right: '20px',
        padding: '12px 20px',
        borderRadius: '6px',
        color: 'white',
        fontSize: '14px',
        fontWeight: '500',
        zIndex: '10000',
        opacity: '0',
        transform: 'translateX(100%)',
        transition: 'all 0.3s ease'
      });

      if (type === 'success') {
        toast.style.background = 'linear-gradient(135deg, #10b981, #059669)';
      } else if (type === 'error') {
        toast.style.background = 'linear-gradient(135deg, #ef4444, #dc2626)';
      } else {
        toast.style.background = 'linear-gradient(135deg, #3b82f6, #2563eb)';
      }

      document.body.appendChild(toast);

      setTimeout(() => {
        toast.style.opacity = '1';
        toast.style.transform = 'translateX(0)';
      }, 100);

      setTimeout(() => {
        toast.style.opacity = '0';
        toast.style.transform = 'translateX(100%)';
        setTimeout(() => {
          if (document.body.contains(toast)) {
            document.body.removeChild(toast);
          }
        }, 300);
      }, 3000);
    },

    async submitType() {
      // 表单验证
      if (!this.currentType.typeName.trim()) {
        this.showToast('请输入类型名称', 'error');
        return;
      }

      try {
        this.loading = true;
        
        if (this.isEditing) {
          // 编辑模式
          const typeData = {
            typeName: this.currentType.typeName.trim(),
            status: this.currentType.status
          };
          
          const result = await this.updateTypeOnServer(this.currentType.typeId, typeData);
          if (result.code === 200) {
            // 重新加载数据
            await this.loadTypes();
            this.showToast(`类型 "${this.currentType.typeName}" 更新成功`, 'success');
          } else {
            this.showToast(result.message || '更新失败', 'error');
            return;
          }
        } else {
          // 添加模式
          const newType = {
            typeName: this.currentType.typeName.trim(),
            status: this.currentType.status
          };
          
          const result = await this.saveTypeToServer(newType);
          if (result.code === 200) {
            // 重新加载数据
            await this.loadTypes();
            this.showToast(`类型 "${this.currentType.typeName}" 创建成功`, 'success');
          } else {
            this.showToast(result.message || '创建失败', 'error');
            return;
          }
        }
        
        this.closeModal();
      } catch (error) {
        this.showToast('网络错误，请重试', 'error');
      } finally {
        this.loading = false;
      }
    }
  }
};
</script>

<style scoped>
/* 页面头部样式 */
.page-header {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 2rem;
  border-radius: 12px;
  margin-bottom: 2rem;
  box-shadow: 0 4px 20px rgba(102, 126, 234, 0.3);
}

.page-header h2 {
  margin: 0 0 0.5rem 0;
  font-size: 2rem;
  font-weight: 700;
}

.page-header p {
  margin: 0;
  opacity: 0.9;
  font-size: 1.1rem;
}

/* 内容包装器 */
.content-wrapper {
  background: white;
  border-radius: 12px;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
  
}

/* 搜索和操作栏样式 */
.search-action-bar {
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  padding: 1.5rem;
  border-bottom: 1px solid #e5e7eb;
  display: flex;
  gap: 1rem;
  align-items: center;
  flex-wrap: wrap;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.search-box {
  position: relative;
  flex: 1;
  min-width: 300px;
}

.search-input {
  width: 100%;
  padding: 0.75rem 3rem 0.75rem 1rem;
  border: 2px solid #e5e7eb;
  border-radius: 8px;
  font-size: 0.875rem;
  transition: all 0.3s ease;
  background: white;
}

.search-input:focus {
  outline: none;
  border-color: #667eea;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.search-btn {
  position: absolute;
  right: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: white;
  border: none;
  padding: 0.5rem;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
}

.search-btn:hover {
  transform: translateY(-50%) scale(1.05);
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.filter-controls {
  display: flex;
  gap: 1rem;
}

.filter-select {
  padding: 0.75rem 1rem;
  border: 2px solid #e5e7eb;
  border-radius: 8px;
  font-size: 0.875rem;
  background: white;
  transition: all 0.3s ease;
  min-width: 150px;
}

.filter-select:focus {
  outline: none;
  border-color: #667eea;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.create-btn {
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: white;
  border: none;
  padding: 0.75rem 1.5rem;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  white-space: nowrap;
}

.create-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(102, 126, 234, 0.3);
}

/* 加载状态样式 */
.loading-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4rem 2rem;
  color: #6b7280;
}

.loading-spinner {
  width: 3rem;
  height: 3rem;
  border: 3px solid #e5e7eb;
  border-top: 3px solid #667eea;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin-bottom: 1rem;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* 空状态样式 */
.empty-state {
  text-align: center;
  padding: 4rem 2rem;
  color: #6b7280;
}

.empty-icon {
  font-size: 4rem;
  margin-bottom: 1rem;
  opacity: 0.5;
}

.empty-state h3 {
  font-size: 1.5rem;
  font-weight: 600;
  color: #374151;
  margin-bottom: 0.5rem;
}

.empty-state p {
  font-size: 1rem;
  margin-bottom: 2rem;
  max-width: 400px;
  margin-left: auto;
  margin-right: auto;
}

/* 类型网格样式 */
.types-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
  gap: 1.5rem;
  padding: 1.5rem;
}

.type-card {
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 12px;
  
  transition: all 0.3s ease;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.type-card:hover {
  transform: translateY(-4px);
  box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15);
  border-color: #667eea;
}

.type-card.inactive {
  opacity: 0.7;
}

.type-info {
  margin-bottom: 1rem;
}

.type-title {
  margin: 0 0 0.5rem 0;
  font-size: 1.25rem;
  font-weight: 600;
  color: #1f2937;
  
  text-overflow: ellipsis;
  white-space: nowrap;
}

.type-meta {
  display: flex;
  gap: 1rem;
  font-size: 0.875rem;
  color: #6b7280;
}

.type-id {
  font-family: 'Monaco', 'Menlo', monospace;
  font-weight: 600;
}

.type-status {
  padding: 0.25rem 0.5rem;
  border-radius: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.status-active {
  background: #d1fae5;
  color: #065f46;
}

.status-inactive {
  background: #fee2e2;
  color: #991b1b;
}

.card-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: center;
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid #e5e7eb;
}

.action-btn {
  width: 2rem;
  height: 2rem;
  border: none;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 0.875rem;
}

.action-btn.edit {
  background: #dbeafe;
  color: #1d4ed8;
}

.action-btn.edit:hover {
  background: #bfdbfe;
  transform: scale(1.1);
}

.action-btn.toggle {
  background: #fef3c7;
  color: #d97706;
}

.action-btn.toggle:hover {
  background: #fde68a;
  transform: scale(1.1);
}

.action-btn.delete {
  background: #fee2e2;
  color: #dc2626;
}

.action-btn.delete:hover {
  background: #fecaca;
  transform: scale(1.1);
}

.card-content {
  padding: 1.5rem;
}

.type-details {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.detail-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.875rem;
}

.detail-row .label {
  color: #6b7280;
  font-weight: 500;
}

.detail-row .value {
  color: #1f2937;
  font-weight: 600;
  text-align: right;
  max-width: 60%;
  
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* 分页样式 */
.pagination-wrapper {
  background: #f8fafc;
  padding: 1.5rem;
  border-top: 1px solid #e5e7eb;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 1rem;
}

.pagination-info {
  color: #6b7280;
  font-size: 0.875rem;
}

.pagination-controls {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.pagination-btn {
  padding: 0.5rem 1rem;
  border: 1px solid #d1d5db;
  background: white;
  color: #374151;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 0.875rem;
}

.pagination-btn:hover:not(:disabled) {
  background: #f3f4f6;
  border-color: #9ca3af;
}

.pagination-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.page-numbers {
  display: flex;
  gap: 0.25rem;
}

.page-number {
  width: 2.5rem;
  height: 2.5rem;
  border: 1px solid #d1d5db;
  background: white;
  color: #374151;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
  font-size: 0.875rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

.page-number:hover {
  background: #f3f4f6;
  border-color: #9ca3af;
}

.page-number.active {
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: white;
  border-color: #667eea;
  box-shadow: 0 2px 8px rgba(102, 126, 234, 0.3);
}

/* 模态框样式 */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
}

.modal-content {
  background: white;
  border-radius: 12px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  max-width: 500px;
  width: 90%;
  max-height: 90vh;
  
  animation: modalSlideIn 0.3s ease-out;
}

@keyframes modalSlideIn {
  from {
    opacity: 0;
    transform: translateY(-20px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.modal-header {
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: white;
  padding: 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h3 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 600;
}

.close-btn {
  background: none;
  border: none;
  color: white;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0.25rem;
  border-radius: 4px;
  transition: all 0.2s ease;
}

.close-btn:hover {
  background: rgba(255, 255, 255, 0.2);
}

.modal-body {
  padding: 2rem;
}

.form-group {
  margin-bottom: 1.5rem;
}

.form-group label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 600;
  color: #374151;
  font-size: 0.875rem;
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 0.75rem 1rem;
  border: 2px solid #e5e7eb;
  border-radius: 8px;
  font-size: 0.875rem;
  transition: all 0.3s ease;
  background: white;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: #667eea;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

.form-textarea {
  resize: vertical;
  min-height: 100px;
  font-family: inherit;
}

.form-actions {
  background: #f8fafc;
  padding: 1.5rem;
  display: flex;
  gap: 1rem;
  justify-content: flex-end;
  border-top: 1px solid #e5e7eb;
}

.btn-secondary {
  background: #f3f4f6;
  color: #374151;
  border: 1px solid #d1d5db;
  padding: 0.75rem 1.5rem;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-secondary:hover {
  background: #e5e7eb;
  border-color: #9ca3af;
}

.btn-primary {
  background: linear-gradient(135deg, #667eea, #764ba2);
  color: white;
  border: none;
  padding: 0.75rem 1.5rem;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s ease;
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 25px rgba(102, 126, 234, 0.3);
}

/* 响应式设计 */
@media (max-width: 768px) {
  .type-list {
    padding: 15px;
  }
  
  .search-action-bar {
    flex-direction: column;
    align-items: stretch;
  }
  
  .search-box {
    min-width: auto;
  }
  
  .filter-controls {
    justify-content: space-between;
  }
  
  .types-grid {
    grid-template-columns: 1fr;
    padding: 1rem;
  }
  
  .pagination-wrapper {
    flex-direction: column;
    gap: 1rem;
  }
  
  .pagination-controls {
    flex-direction: column;
    gap: 1rem;
  }
  
  .modal-content {
    margin: 1rem;
    width: calc(100% - 2rem);
  }
  
  .modal-body {
    padding: 1.5rem;
  }
}
</style>